<?php
/**
*
* @author chenping<chenping@shopex.cn>
* @version $Id: 2013-3-12 17:23Z
*/
class erpapi_shop_response_plugins_order_orderextend extends erpapi_shop_response_plugins_order_abstract
{
    public function convert(erpapi_shop_response_abstract $platform)
    {
        $extend = array();

        if ($platform->_ordersdf['sellermemberid']) {
            $extend['sellermemberid'] = $platform->_ordersdf['sellermemberid'];
        }

        // 保存报关号
        if ($platform->_ordersdf['payment_no']) {
          $extend['contents']['custom_info']['payment_no'] =  $platform->_ordersdf['payment_no'];
        }

        if ($platform->_ordersdf['gateway_name']) {
          $extend['contents']['custom_info']['gateway_name'] = $platform->_ordersdf['gateway_name'];
        }

        return $extend;
    }

    /**
     *
     * @return void
     * @author 
     **/
    public function postCreate($order_id,$extendinfo)
    {
        $orderExtendObj = app::get('ome')->model('order_extend'); 
        
        if ($extendinfo['contents']) {      
          // 判断contents是否有值
          $row = $orderExtendObj->getList('contents',array('order_id'=>$order_id));
          if ($row && $row[0]['contents']) {
            $contents = @unserialize($row[0]['contents']);

            $newcontents = array_merge((array)$contents,$extendinfo['contents']);

            $extendinfo['contents'] = serialize($newcontents);
            if ($contents == $newcontents) {
               unset($extendinfo['contents']);
            }
            
          }
        }

        if ($extendinfo) {
          $extendinfo['order_id'] = $order_id;
          $orderExtendObj->save($extendinfo);
        }
        
    }

  /**
   *
   * @param Array 
   * @return void
   * @author 
   **/
  public function postUpdate($order_id,$extendinfo)
  {
    $orderExtendObj = app::get('ome')->model('order_extend'); 



    if ($extendinfo['contents']) {      
      // 判断contents是否有值
      $row = $orderExtendObj->getList('contents',array('order_id'=>$order_id));
      if ($row && $row[0]['contents']) {
        $contents = @unserialize($row[0]['contents']);

        $newcontents = array_merge((array)$contents,$extendinfo['contents']);

        $extendinfo['contents'] = serialize($newcontents);
        if ($contents == $newcontents) {
           unset($extendinfo['contents']);
        }
      }
    }

    if ($extendinfo) {
      $extendinfo['order_id'] = $order_id;
      $orderExtendObj->save($extendinfo);
    }  
  }
}